<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.transcargo.users.Contact" %>
<%@ page import="com.transcargo.users.User" %>
<%@ page import="com.transcargo.users.Transport" %>
<%@ page import="com.transcargo.errors.ErrorList" %>
<%@ page import="com.transcargo.data.CountriesData" %>
<%@ page import="com.transcargo.geo.Country" %>
<%@ page import="com.transcargo.geo.Region" %>
<%@ page import="com.transcargo.geo.City" %>
<%@ page import="java.util.Date" %>
<%@include file="header.jsf"%>
<%@include file="session.jsf"%>
<%@include file="resolve_country.jsf"%>
<%
    if (User_Id <= 0) {
        response.sendRedirect("auth.jsp");
        return;
    }
	Date date_from = new Date();
	Date date_to = new Date(date_from.getTime() + 86400000);
    Country[] countries = CountriesData.getCountries(dbase);
	String truck_id = request.getParameter("truck");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  	<head><title>TransCargo</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="ajaxrequest.js"></script>
<script type="text/javascript">

var num_countries=<%=countries.length%>;
var Countries=new Array();
var CountryValues=new Array();
<%
    for (int i = 0; i < countries.length; i++) {
        Country country = countries[i];
        out.println("Countries[" + i + "]='" + country.getName() + "';");
        out.println("CountryValues[" + i + "]='" + country.getId() + "';");
    }
    iter = null;
    list = dbase.execute("SELECT max(id) from transport_loading");
    if (list != null) iter = list.iterator();
       if (iter.hasNext()) {
    	   String[] ctr = iter.next();
    	   out.println("var maxLds = " + ctr[0]);
       }
%>
var cid = <%=country_id%>;

</script>
      <script type="text/javascript" src="chooseareas.js"></script>
      <script type="text/javascript" src="forms.js"></script>
	<link type="text/css" href="transcargo.css" rel="stylesheet"/>
  </head>
  <body onload="initTransport();">
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr><td>
			<%@include file="page_header.jsf"%>
        </td></tr>
        <tr><td align="center">
            Добавление свободного транспорта<br>
			<div id="ErrorPlaceHolder" class="errorString"><br><br></div>
            <form action="PostFreightAction" method="POST" target="ifPost">
            <table border="0" cellpadding="0" cellspacing="0" width="490">
                <tr class="tdFormSearch" valign="middle"><td><b>Дата загрузки:</b></td><td align="left" valign="middle"><input type="radio" name="datetype" value="on" checked> с <input name="date_from" id="date_from" value="<%=date_from.getDate()%>.<%=date_from.getMonth()+1%>.<%=date_from.getYear()+1900%>" size="8" onfocus="gfPop.fPopCalendar(document.getElementById('date_from'));return false;"> по <input name="date_to" id="date_to" value="<%=date_to.getDate()%>.<%=date_to.getMonth()+1%>.<%=date_to.getYear()+1900%>" size="8" onfocus="gfPop.fPopCalendar(document.getElementById('date_to'));return false;"></td></tr>
                <tr class="tdFormSearch"><td>&nbsp;</td><td align="left"><input type="radio" name="datetype" value="off">Постоянно</td></tr>
                <tr class="tdFormSearch"><td><b>Место загрузки:</b></td><td align="left"><input name="from" id="from" size="20" onfocus="toggleFrom(true)" onblur="toggleFrom(false)" onChange="changeFrom()" onkeyup="changeFrom()">
						(<a id="FRegionPlace">укажите пункт</a>)
						<input type="hidden" name="regfrom" id="regFrom"><br>
						<div id="FromPlaceHolder" style="position: absolute;visibility:hidden;z-index: 999;"></div></td></tr>
                <tr class="tdFormSearch"><td><b>Место выгрузки:</b></td><td align="left"><input name="to" id="to" size="20" onfocus="toggleTo(true)" onblur="toggleTo(false)" onChange="changeTo()" onkeyup="changeTo()">
						(<a id="TRegionPlace">любое направление</a>)
						<input type="hidden" name="regto" id="regTo"><br>
						<div id="ToPlaceHolder" style="position: absolute;visibility:hidden;z-index: 999;"></div></td></tr>
                <tr><td colspan="2"><hr></td></tr>
<%
	if (user.getNumTransports() > 0) {
		Transport[] tp = user.getTransport();
%>
                <tr><td class="tdFormSearch"><b>Свой транспорт:</b></td><td align="left"><select name="owntransport" id="own_transport" class="selNormal" onchange="changeTransport(this);">
				<option value="">Не используется</option>
<%
				for (int i = 0; i < tp.length; i++)
					if (truck_id != null && Integer.parseInt(truck_id) == tp[i].getId()) {
%>				<option value="<%=tp[i].getId()%>" selected><%=tp[i].getName()%></option><%
						
					} else {
%>				<option value="<%=tp[i].getId()%>"><%=tp[i].getName()%></option><%
				}
	}
%>
				</select></td></tr>
                <tr><td class="tdFormSearch"><b>Тип транспорта:</b></td><td align="left"><select name="cargo_type" id="cargo_type" class="selNormal">
					<%
					        iter = null;
					        list = dbase.execute("SELECT id, name from transport_type");
					        if (list != null) iter = list.iterator();
					        if (iter != null) {
					            while (iter.hasNext()) {
					                String[] str = iter.next();
					                %><option value="<%=str[0]%>"><%=str[1]%></option><%
					            }
					        }
					%>
				    </select></td></tr>
                <tr><td class="tdFormSearch"><b>Тип загрузки:</b></td><td align="left">
                    <%
				        iter = null;
				        list = dbase.execute("SELECT id, name from transport_loading");
				        if (list != null) iter = list.iterator();
			            while (iter.hasNext()) {
			                String[] str = iter.next();
			                %><input type="checkbox" name="load<%=str[0]%>"><%=str[1]%><br><%
			            }
				%>
                </td></tr>
                <tr class="tdFormSearch"><td><b>Объем:</b></td><td align="left"><input name="volume" size="10"> м<sup>3</sup></td></tr>
                <tr class="tdFormSearch"><td><b>Тоннаж:</b></td><td align="left"><input name="tonnage" size="10"> т.</td></tr>
                <tr class="tdFormSearch"><td>Длина:</td><td align="left"><input name="length" size="10"> м.</td></tr>
                <tr class="tdFormSearch"><td>Высота:</td><td align="left"><input name="height" size="10"> м.</td></tr>
                <tr class="tdFormSearch"><td>Ширина:</td><td align="left"><input name="width" size="10"> м.</td></tr>
                <tr class="tdFormSearch"><td>TIR Carnet:</td><td align="left"><input type="checkbox" name="tir"></td></tr>
                <tr class="tdFormSearch"><td>EKMT:</td><td align="left"><input type="checkbox" name="ekmt"></td></tr>
                <tr class="tdFormSearch"><td>Класс ADR:</td><td align="left"><select name="adr">
                    <option value="">-</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                    <option value="7">7</option>
                    <option value="8">8</option>
                    <option value="9">9</option>
                </select></td></tr>
                <tr><td colspan="2"><hr></td></tr>
                <tr class="tdFormSearch"><td>Форма оплаты:</td><td align="left"><select name="payment_type" id="payment_type" class="selNormal">
					<%
					        iter = null;
					        list = dbase.execute("SELECT id, name from payment_types");
					        if (list != null) iter = list.iterator();
					        if (iter != null) {
					            int i = 0;
					            while (iter.hasNext()) {
					                String[] str = iter.next();
					                %><option value="<%=str[0]%>"><%=str[1]%></option><%
					                i++;
					            }
					        }
					%>
				    </select></td></tr>
                <tr class="tdFormSearch"><td>Ставка:</td><td align="left"><input name="bid" size="5"><select name="payment_curr" id="payment_curr" class="selShort">
				<%
					        iter = null;
					        list = dbase.execute("SELECT id, name from payment_currencies");
					        if (list != null) iter = list.iterator();
					        if (iter != null) {
					            int i = 0;
					            while (iter.hasNext()) {
					                String[] str = iter.next();
					                %><option value="<%=str[0]%>"><%=str[1]%></option><%
					                i++;
					            }
					        }
					%>
					<option value="-">Договорная</option>
				</select></td></tr>
                <tr class="tdFormSearch"><td>&nbsp;</td><td align="left"><input type="checkbox" name="urgent"><b>Срочно! (загрузить до <input name="urgenttime" size="5" value="12:00">)</b></td></tr>
                <tr class="tdFormSearch"><td>&nbsp;</td><td align="left"><input type="checkbox" name="passing">Попутный транспорт</td></tr>
                <tr class="tdFormSearch"><td>Примечание:</td><td align="left"><input name="comments" size="30"></td></tr>
<% 
	if (user.getNumContacts() > 0) {
%>
                <tr><td colspan="2"><hr></td></tr>
                <tr class="tdFormSearch"><td>Контакт:</td><td align="left"><select name="contact" class="selNormal"><option value="">Общий (<%=user.getName() %>)</option>
<%
	Contact[] cts = user.getContacts();
	for (int i = 0; i < cts.length; i++) out.println("<option value=\"" + cts[i].getId() + "\">" + cts[i].getName() + "</option>");
}
%>
                <tr><td class="tdFormSearch"><input type="submit" value="Продолжить"></td><td align="left"><input type="submit" value="Отмена" onclick="gouser();return false;"></td></tr>
            </table>
            </form>
        </td></tr>
        </table>
	<iframe name="ifPost" id="ifPost" width="0" height="0" style="visibility: hidden;width: 0;height: 0;" onload="handlePost(this);" onload="handlePost(this);"></iframe>
	<iframe width=174 height=189 name="gToday:cal:none" id="gToday:cal:none" src="calendar/cal.htm" scrolling="no" frameborder="0" style="visibility:visible; z-index:999; position:absolute; top:-500px; left:-500px;"></iframe>
<script type="text/javascript">
	var ef = document.getElementById('FromPlaceHolder');
	var et = document.getElementById('ToPlaceHolder');
	AddSearchArea('From',ef);
	AddSearchArea('To',et);
</script>
  </body>
</html>
